using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SQLDAL;
using System.Data.SqlClient;

/// <summary>
/// Summary description for RestaurantBll
/// </summary>
public class RestaurantBll
{
	public RestaurantBll()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    #region List all Restaurant
    public SqlDataReader ListAllRestaurant()
    {
        return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_Restaurant_ListAll", null);
    }
    #endregion

    #region Create new Restaurant
    public int createRestaurant(RestaurantInfo resInfo)
    {
        SqlParameter[] cmdParms =
            {
                new SqlParameter("@resID", SqlDbType.VarChar, 10),
                new SqlParameter("@resName", SqlDbType.VarChar, 100),
                new SqlParameter("@phone", SqlDbType.VarChar, 12),
                new SqlParameter("@address", SqlDbType.VarChar, 100),
                new SqlParameter("@resPicture", SqlDbType.VarChar, 200),
                new SqlParameter("resDescription", SqlDbType.VarChar, 1000)
            };
        cmdParms[0].Value = resInfo.ResID;
        cmdParms[1].Value = resInfo.ResName;
        cmdParms[2].Value = resInfo.Phone;
        cmdParms[3].Value = resInfo.Address;
        cmdParms[4].Value = resInfo.ResPicture;
        cmdParms[5].Value = resInfo.ResDescription;

        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_Restaurant_Create", cmdParms);

        return result;
    }
    #endregion

    #region Update Restaurant's Information
    public int UpdateRestaurant(RestaurantInfo resInfo)
    {
        SqlParameter[] cmdParms =
            {
                new SqlParameter("@resID", SqlDbType.VarChar, 10),
                new SqlParameter("@resName", SqlDbType.VarChar, 100),
                new SqlParameter("@phone", SqlDbType.VarChar, 12),
                new SqlParameter("@address", SqlDbType.VarChar, 100),
                new SqlParameter("@resPicture", SqlDbType.VarChar, 200),
                new SqlParameter("resDescription", SqlDbType.VarChar, 1000)
            };
        cmdParms[0].Value = resInfo.ResID;
        cmdParms[1].Value = resInfo.ResName;
        cmdParms[2].Value = resInfo.Phone;
        cmdParms[3].Value = resInfo.Address;
        cmdParms[4].Value = resInfo.ResPicture;
        cmdParms[5].Value = resInfo.ResDescription;

        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_Restaurant_Update", cmdParms);

        return result;
    }

    #endregion

    #region Delete Restaurant
    public int DeleteRestaurant(RestaurantInfo resInfo)
    {
        SqlParameter[] cmdParms =
            {
                new SqlParameter("@resID", SqlDbType.VarChar, 10)
            };
        cmdParms[0].Value = resInfo.ResID;

        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_Restaurant_Delete", cmdParms);
        return result;
    }
    #endregion

    #region Load restaurant to the drop down list
    public void LoadRestaurant(DropDownList dropDownList)
    {

        DataSet ds = SQLDAL.SQLHelper.GetDataSetUsingSP(CommandType.StoredProcedure, 
            "sp_Restaurant_ListAll", "Restaurant", null);
        dropDownList.DataSource = ds.Tables["Restaurant"];
        dropDownList.DataTextField = "resName";
        dropDownList.DataValueField = "resID";
        dropDownList.DataBind();
        dropDownList.Items.Insert(0, "--Select restaurant--");
    }
    #endregion

    #region List resID by resName
    public string ListResID(RestaurantInfo resInfo)
    {
        SqlParameter[] cmdParms = {
            new SqlParameter("@resName", SqlDbType.VarChar, 100)
        };
        cmdParms[0].Value = resInfo.ResName;
        return SQLHelper.ExecuteScalar(SQLHelper.CONN_STRING, CommandType.StoredProcedure,
                                        "sp_Restaurant_ListResIDByResName", cmdParms).ToString();
    }
    #endregion

    /// <summary>
    /// Add function by PHUONG
    /// Date: 9/5/2009
    /// </summary>
    /// <param name="foodInfo"></param>
    /// <returns></returns>
    /// 
    #region List Details Restaurant

    public SqlDataReader ListDetailsRestaurant(RestaurantInfo resInfo)
    {
        SqlParameter[] parms = { 
                new SqlParameter("@resID", SqlDbType.VarChar, 10)};
        parms[0].Value = resInfo.ResID;

        return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_Restaurant_ListDetailsRestaurant", parms);
    }
    #endregion

    #region List Restaurant by restaurant name when search 
    public void ListRestaurantByRestaurantName(RestaurantInfo resInfo, DataList dataList )
    {
        SqlParameter[] parms = {
            new SqlParameter("@resName", SqlDbType.VarChar, 10)};
        parms[0].Value = resInfo.ResName;
        DataSet ds = SQLHelper.GetDataSetUsingSP(CommandType.StoredProcedure,
            "sp_Restaurant_SearchRestaurantByRestaurantName", "Restaurant", parms);
        dataList.DataSource = ds.Tables["Restaurant"];
        dataList.DataBind();
    }
    #endregion
}
